package dao

import (
	"context"
	"sale-admin/internal/models"

	"gorm.io/gorm"
)

type OrderUserAddress struct{}

func (OrderUserAddress) Create(
	ctx context.Context,
	db *gorm.DB,
	record models.OrderShipmentInfo,
) (string, error) {
	err := db.WithContext(ctx).Model(&models.OrderShipmentInfo{}).Create(&record).Error
	return record.ID, err
}

func (OrderUserAddress) Detail(
	ctx context.Context,
	db *gorm.DB,
	outTradeNo string,
) *models.OrderShipmentInfo {
	var record models.OrderShipmentInfo
	rowsAffected := db.WithContext(ctx).Model(&models.OrderShipmentInfo{}).
		Where("out_trade_no = ?", outTradeNo).
		Take(&record).RowsAffected
	if rowsAffected <= 0 {
		return nil
	}
	return &record
}
